package com.chris.homecare.screens.events
{
	import com.chris.homecare.components.renderers.EventListRenderer;
	import com.chris.homecare.data.DataUtil;
	import com.chris.homecare.utils.CommonUtils;
	
	import feathers.controls.Label;
	import feathers.controls.List;
	import feathers.controls.Screen;
	import feathers.controls.renderers.IListItemRenderer;
	import feathers.data.ListCollection;
	
	import starling.display.Quad;
	
	public class EventsListScreen extends Screen
	{
		private var eventList:List;
		private var eventsListCollection:ListCollection;

		private var noEventLable:Label;
		
		public function EventsListScreen()
		{
			super();
			eventsListCollection = DataUtil.getNextTenDaysEvents(new Date);
		}
		
		override protected function initialize():void
		{
			eventList = new List();
			eventList.dataProvider = eventsListCollection;
			eventList.itemRendererFactory = function ():IListItemRenderer
			{
				var renderer:EventListRenderer = new EventListRenderer();
				return renderer;
			};
			addChild(eventList);
			eventList.backgroundSkin = new Quad(10,10,0xFFFFFF);
			eventList.backgroundDisabledSkin = new Quad(10,10,0xFFFFFF);
			
			noEventLable = new Label();
			noEventLable.text = "No events for the next 10 days";
			noEventLable.x = noEventLable.y = 20*CommonUtils.scaleValue;
			noEventLable.nameList.add("no-message-lbl");
			addChild(noEventLable);
			
			super.initialize();
		}
		
		override protected function draw():void
		{
			eventList.width = this.width;
			eventList.height = this.height;
			
			if(eventsListCollection.data.length == 0)
			{
				noEventLable.visible = true;
				noEventLable.includeInLayout = true;
			}
			
			else
			{
				noEventLable.visible = false;
				noEventLable.includeInLayout = false;
			}
			
			super.draw();
		}
		
	}
}